
 <template>
 	<el-dialog title="" visible :show-close="false" :modal-append-to-body="false" class="wrap" size="tiny">
 		<i class="el-icon-close close" @click="cancel" style="color: white;z-index:10;"></i>
	    <div class="bt">修复</div>
 		<el-form label-width="100px" class="form">
 			<el-form-item label="物品名称">
 				<el-input v-model="form.wpmc" :readonly="true" placeholder="请输入数量" class="select-block"></el-input>
 		    </el-form-item>
 			<el-form-item label="报修数量">
 				<el-input v-model="form.bxsl" :readonly="true" placeholder="请输入数量" class="select-block"></el-input>
 		    </el-form-item>
 			<el-form-item label="修好数量">
 				<el-input v-model="xhsl"  placeholder="请输入数量" class="select-block"></el-input>
 		    </el-form-item>
 		    <el-form-item label="报损数量" v-if='yc'>
 				<el-input v-model="form.bssl"  :disabled="true" placeholder="请输入数量" class="select-block"></el-input>
 		    </el-form-item> 
		    <el-form-item label="报损原因"  v-if='yc' style='margin-bottom: 5px;'>
 				<el-input v-model="yy" type="textarea" :rows="2"  placeholder="请输入未修好原因" class="select-block"></el-input>
	 		</el-form-item>
	 		<span style="color: red;">注：当修改数量小于报修数量时，系统会自动将未修好的数量计入报损数量</span>
	 	</el-form>
	 		<el-button type="primary" class="submit" :disabled="jy" @click="submit">修复</el-button>
	 		<el-button type="danger" class="submit"  @click="cancel">退出</el-button>
 	</el-dialog>
 </template>
 <script type="text/javascript">
 	import qs from 'qs'
 	export default {
 		props: ['params'],
 		data() {
 			return {
 				yc:false,
 				form: {
 					wpmc:'',
 					   bxsl:'',
//			           wpid :'',
			           bssl:'',
			           bsyy :'',
 					   id:''
 				},
 				 xhsl:'',
			     yy:'',
 				 jy:true,
 			}
 		},
 		created() {
  		 this.form.id = this.params.row.id;
          this.loadinfo();
 		},
 		watch:{
            'xhsl': function(newVal,oldVal){
            	 if (!newVal){ 
            	 	this.jy=true;
            	 	this.yc=false; 
                	this.form.bssl='';
                	this.yy='';
            	 	return  ;
            	 }
            	 
                if(parseInt(newVal) < parseInt(this.form.bxsl)) {
                	this.yc=true;
                	this.jy =true;
                	this.form.bssl=parseInt(this.form.bxsl)-parseInt(newVal);
                }else if(parseInt(newVal) >= parseInt(this.form.bxsl)){
                	this.yc=false;
                	this.form.bssl='';
                	this.jy =false;
                	this.yy='';
                } 
            },
             'yy': function(newVal,oldVal){
             	this.jy=true;
             	if( newVal && this.form.bssl ){ 
             	 	this.jy=false; 
             	} else if( !newVal && !this.form.bssl ){ 
             	 	this.jy=false;
             	}
             }
        },
 		methods: {
 			loadinfo(){
 				 var logininfo = JSON.parse(localStorage.logininfo) ;
		         var params3 = qs.stringify({
		           xxid:logininfo.xxid,
		           yhid:logininfo.id,
		           id:this.form.id
		  				});
 				 this.axios.post(this.$store.state.api+'wpbx/info',params3)
                 .then( res =>  {
 							this.form=res.data.data
 					 }).catch(res => {
 						 this.$message.warning("服务器异常");
 			 				this.$emit('close', { type: 'info', cancel: true });
 					 })
 			},
 			 submit() {
 				//检测
 				this.$store.state.loading = true;
 				 if(!this.xhsl) {
				 	this.$message.warning('请输入修好数量');
				 	this.$store.state.loading = false;
				 	return;
 				}
 				//装载数据
 				var logininfo = JSON.parse(localStorage.logininfo);
 				var params2 = qs.stringify({
 						id: this.form.id,
 						xhsl: this.xhsl,
 						yy: this.yy,
 						yhid: logininfo.id,
 						xxid: logininfo.xxid
 					})
 				//执行
 				    this.axios.post(this.$store.state.api + 'wpbx/check',  params2 )
 						.then(res => {
 							
 							if(res.data.code == 1) {
 								this.$emit('close', { type: 'sh', cancel: false });
 								this.$store.state.loading = false;
 							} else {
 								this.$emit('close', { type: 'sh', cancel: false });
 								this.$store.state.loading = false;
 							}
 						}).catch(res => {
 							this.$message.warning("服务器异常");
 							this.$store.state.loading = false;
 						})
 			},
 			cancel() {
 				this.$emit('close', { type: 'sh', cancel: true })
 			}
 		},
// 		computed: {
//        thje(){
//          let number = this.form.wpdj * this.form.sl ;
//          if (number<=0) {
//            return 0.00
//          }else if(number<=this.form.kcsl*this.form.wpdj){
//          	return number
//          }else{
//          	this.$message.warning('输入退货数量有误')
//          }
//        },
//        }
 	}
 </script>
 <style lang="less" scoped>
 	.wrap {
 		text-align: center;
 	}
 	.bt{
		position: absolute;
		width: 100%;
		height: 50px;
		margin: 0 auto;
		top: 0;
		left: 0;
		background: #50BFFF;
		color:white;
		text-align:left;
		line-height: 50px;
		font-size: 17px;
		padding-left: 15px;
	}
 	.form {
 		text-align: left;
 		margin-top: 10px;
 	}
 	.el-form-item {
    margin-bottom: 22px;
}
 	.input {
             width: 300px;
             display: inline-block;
    }
    .input1 {
			width: 220px;
			display: inline-block;
		}
 	.select-block {
 		display: block;
 	}
 	.submit {
 		width: 120px;
 	}
 	.wpfl{
 			width: 218%;
 			height: 98%;
			background: #fff;
			position: absolute;
			top: 5px;
			left: -250px;
		}
 </style>
